PHP code to convert text blocks indented by four spaces into a <pre><code> block [Markdown]
Posted
by Alfonso
on Stack Overflow
See other posts from Stack Overflow
or by Alfonso
Published on 2010-03-31T07:15:34Z
Indexed on
2010/03/31
7:23 UTC
Read the original article
Hit count: 371
Hi,
I'm not very good at PHP and would like to have a PHP function which turns this (text block indented by four spaces):
printf("goodbye world!"); /* his suicide note
was in C */
Into this:
<pre><code> printf("goodbye world!"); /* his suicide note
was in C */</code></pre>
This is what Markdown does. I found this PHP port of Markdown (see function doCodeBlocks()
), but I don't want to use the entire Markdown file, I just want this one function.
Can someone provide me with the minimal PHP code required to get this to work? So I can do this:
<?php echo markdownPre('Here goes some code:
var x = 1, y = 2;
alert(x + y);
That should be a pre block.'); ?>
© Stack Overflow or respective owner